<template>
  <div class="basic-elements">
    <div class="elements-header">
      <h4>基础要素</h4>
    </div>
    
    <div class="elements-grid">
      <div class="element-row">
        <div class="element-item" @click="$emit('add-element', 'text')">
          <div class="element-icon">T</div>
          <div class="element-name">文字</div>
        </div>
        <div class="element-item" @click="$emit('add-element', 'rectangle')">
          <div class="element-icon">□</div>
          <div class="element-name">矩形</div>
        </div>
        <div class="element-item" @click="$emit('add-element', 'circle')">
          <div class="element-icon">○</div>
          <div class="element-name">圆形</div>
        </div>
      </div>
      
      <div class="element-row">
        <div class="element-item" @click="$emit('add-element', 'triangle')">
          <div class="element-icon">△</div>
          <div class="element-name">三角形</div>
        </div>
        <div class="element-item" @click="$emit('add-element', 'polygon')">
          <div class="element-icon">⬡</div>
          <div class="element-name">多边形</div>
        </div>
        <div class="element-item" style="visibility: hidden"></div>
      </div>
    </div>
    
    <div class="divider"></div>
    
    <div class="elements-header">
      <h4>绘制元素</h4>
    </div>
    
    <div class="elements-grid">
      <div class="element-row">
        <div class="element-item" @click="$emit('add-element', 'brush')">
          <div class="element-icon"><i class="el-icon-brush"></i></div>
          <div class="element-name">画笔</div>
        </div>
        <div class="element-item" @click="$emit('add-element', 'line')">
          <div class="element-icon">╱</div>
          <div class="element-name">直线</div>
        </div>
        <div class="element-item" style="visibility: hidden"></div>
      </div>
    </div>
    
    <div class="divider"></div>
    
    <div class="elements-header">
      <h4>快捷导航</h4>
    </div>
    
    <div class="elements-grid">
      <div class="element-row">
        <div class="element-item" @click="$emit('toggle-grid')">
          <div class="element-icon"><i class="el-icon-set-up"></i></div>
          <div class="element-name">网格</div>
        </div>
        <div class="element-item" @click="$emit('toggle-ruler')">
          <div class="element-icon"><i class="el-icon-ruler"></i></div>
          <div class="element-name">标尺</div>
        </div>
        <div class="element-item" style="visibility: hidden"></div>
      </div>
    </div>
    
    <div class="divider"></div>
    
    <div class="elements-header">
      <h4>配色</h4>
    </div>
    
    <div class="color-picker">
      <el-color-picker 
        v-model="currentColor" 
        @change="colorChanged"
        show-alpha
      />
    </div>
    
    <div class="divider"></div>
    
    <div class="elements-header">
      <h4>素材</h4>
    </div>
    
    <div class="material-items">
      <div 
        v-for="(material, index) in materials" 
        :key="index" 
        class="material-item"
        @click="$emit('add-material', material)"
      >
        <img :src="material.url" :alt="material.name" />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';

const emit = defineEmits(['add-element', 'toggle-grid', 'toggle-ruler', 'color-change', 'add-material']);

const currentColor = ref('#FF5722');

const colorChanged = (color) => {
  emit('color-change', color);
};

// 示例素材
const materials = [
  { name: '花朵', url: '/images/materials/flower.svg' },
  { name: '星星', url: '/images/materials/star.svg' },
  { name: '图表', url: '/images/materials/chart.svg' },
  { name: '徽章', url: '/images/materials/badge.svg' },
];
</script>

<style scoped>
.basic-elements {
  padding: 10px;
}

.elements-header {
  margin-bottom: 12px;
}

.elements-header h4 {
  margin: 0;
  font-size: 14px;
  color: #333;
}

.elements-grid {
  margin-bottom: 15px;
}

.element-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.element-item {
  width: 60px;
  height: 60px;
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  background-color: #fff;
}

.element-item:hover {
  border-color: #409EFF;
  background-color: #F2F8FF;
}

.element-icon {
  font-size: 22px;
  margin-bottom: 5px;
  color: #606266;
}

.element-name {
  font-size: 12px;
  color: #606266;
}

.color-picker {
  margin-bottom: 15px;
  display: flex;
  justify-content: center;
}

.material-items {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 15px;
}

.material-item {
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
  cursor: pointer;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f5f5f5;
}

.material-item:hover {
  border-color: #409EFF;
}

.material-item img {
  max-width: 80%;
  max-height: 80%;
  object-fit: contain;
}

.divider {
  height: 1px;
  background-color: #e0e0e0;
  margin: 15px 0;
}
</style>